package com.sunstar.cwcamerademo

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.util.Log
import com.hjjt.cameralib.CameraHelperImpl
import kotlinx.coroutines.*
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.coroutineContext

class Splash : AppCompatActivity(), CoroutineScope by MainScope() {
    val testViewModel = TestViewModel.instance

    var handler: Handler? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash)
        CameraHelperImpl.cameraOpenError = { funName, code ->
            Log.e("Splash", "cameraOpenError: fun:${funName},code:${code}")
            launch(Dispatchers.Main) {
                testViewModel.stopTester()
            }

        }
        UsbHelper().apply {
            bindActivity(this@Splash)
            getUsbDevice(this@Splash)
            allPermissionHasRequestCallBack = {
                unBindActivity(this@Splash)
                launch(Dispatchers.Main) {
                    Log.e(TAG, "allPermissionHasRequestCallBack: ", )
                    withContext(Dispatchers.IO) {
                        testViewModel.getColdNum()
                        testViewModel.checkIsTester()
                        testViewModel.getBootType()
                    }
                    Log.e(TAG, "startActivity: ", )
                    startActivity(Intent(this@Splash, TesterPage::class.java))
                }

            }
        }
    }

    override fun onResume() {
        super.onResume()
    }

    fun test2Main() {

    }

}